from django.db import models

from django.db.models.fields import AutoField


class UnsignedBigAutoField(AutoField):
    def db_type(self, connection):
        return "bigint UNSIGNED AUTO_INCREMENT"

    def rel_db_type(self, connection):
        return "bigint UNSIGNED"


class MessageEvents(models.Model):
    id = UnsignedBigAutoField(
        primary_key=True,
        help_text="pri_id",
    )

    created_at = models.BigIntegerField(
        help_text="创建时间 millsec",
    )
    updated_at = models.BigIntegerField(
        help_text="更新时间 millsec",
    )

    serial_number = models.CharField(unique=True, max_length=191, help_text="serial")
    event = models.CharField(max_length=191, help_text="event")
    status = models.PositiveIntegerField(help_text="status")
    failed_code = models.PositiveIntegerField(help_text="failed_code")

    class Meta:
        managed = True
        db_table = "message_events"
        verbose_name = "message_events kafka"
